/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.service;

import br.com.foxline.clinicplus.entity.Groups;
import br.com.foxline.clinicplus.entity.SystemUser;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author ely
 */
@Stateless
public class GroupService extends GenericService<Groups> {

    public GroupService() {
        super(Groups.class);
    }

    public List<Groups> findGroups(SystemUser u) {
        String sql = "SELECT g FROM SystemUser u JOIN u.groups g WHERE u.id = :id";
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", u.getId());
        return (List<Groups>) query.getResultList();
    }

    public Groups getMedico() {
        String sql = "SELECT g FROM Groups g WHERE g.name like :id";
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", "MEDICO");
        System.err.println("Medicooo: "+query.getSingleResult());
        return (Groups) query.getSingleResult();
    }
}
